<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1"/>
    <title>Title</title>
    <script src="js/vue.js"></script>
    <script src="js/vue-router.js"></script>
</head>
<body>
    <div id="app">
        <router-link to="/home">home</router-link>
        <router-link to="/list">list</router-link>
        <router-view></router-view>
    </div>
    <script>
        let home = {
            template: `
              <div>
              <div>home---{{ $route.query.name }}</div>
              <button @click="goList">点击跳转到list</button>
              </div>
            `,
            methods: {
                goList() {
                    this.$router.push({
                        name: "list", params: {
                            id: 10
                        }
                    })
                }
            }
        }
        let list = {
            template: `
              <div>
              <div>list---{{ $route.params.id }}</div>
              <button @click="goHome">点击跳转到home</button>
              </div>
            `,
            methods: {
                goHome() {
                    this.$router.push({path: "/home", query: {name: "zs"}})
                }
            }
        }
        let router = new VueRouter({
            mode: "history",
            routes: [
                {name: "home", path: "/home", component: home},
                {name: "list", path: "/list", component: list}
            ]
        })
        let vm = new Vue({
            el: "#app",
            data: {},
            methods: {},
            router
        });
    </script>
</body>
</html>